<?php
class TimeUtilityHelper extends AppHelper {


    function minuteToHourMinute($min = 0) {
		if($min>0) {
				$h = floor($min / 60);
				$m = $min - ($h*60);
		} else {
			$h = 0;
			$m = 0;
		}
		return array($h, $m);
    }
	
	function parseTag($value, $key) {
		switch ($key) {
			case 'time':
				return $this->timeTag($value);
			break;
			case 'distance':
				return '<span class="strong">' . $value . '</span>' . __('km', true);
			break;
			case 'calories':
				return '<span class="strong">' . $value . '</span>' . __('kcal', true);
			break;
			case 'procent':
				return '<span class="strong">' . $value . '</span>' . __('%', true);
			break;
			case 'heartrate':
				return '<span class="strong">' . $value . '</span>' . __('bpm', true);
			break;
			case 'power_zone':
				$return = '<div class="hr-zone-widget">';
				if(!is_numeric($value)) {
					$value = 1;
				}
				for($i = 1; $i <=5; $i++) {
					$class="zone" . $i;
					if ($i <= $value) {
						$return = $return . '<strong class="zone'.$i.'">(*)</strong>';
					} else {
						$return = $return . '<strong>*</strong>';
					}

				}
				return $return;
			break;
			default:
				return '<span class="strong">' . $value . '</span>';
			break;
		}
	}
	
	function timeTag($min = 0) {
		$time = $this->minuteToHourMinute($min);
		return '<span class="strong">' . $time[0] . '</span>' . __('h', true).S. '<span class="strong">' . $time[1] . '</span>' . __('m', true);
	}

}

?>